package com.jxnu.duewang.zmly.zhangHaoQi;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.List;
import java.util.Objects;

/**
 * Created by lenovo on 2016/12/7.
 */

public class Footviewpageadapter extends PagerAdapter{
    private List<Bottomimage> list;
    private Context context;

    public Footviewpageadapter(List<Bottomimage> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view=null;
        ImageView imageView=new ImageView(context);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Picasso.with(context).load(list.get(position).getCover()).into(imageView);
        view=imageView;
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
           if(object instanceof View){
               View view= (View) object;
               container.removeView(view);
           }
    }
}
